package Ctr;

import DB.DBPerson;
import Model.*;

public class CtrPerson 
{
	private DBPerson dbPer;
	private CtrRabat ctrRab;
	private CtrPostnrby ctrPos;
	private CtrVare ctrVar;
	
	public CtrPerson()
	{
		dbPer = new DBPerson();
		ctrRab = new CtrRabat();
		ctrPos = new CtrPostnrby();
		ctrVar = new CtrVare();
	}
	
	public Person findPerson(String tlfnr)
	{
		Person p = dbPer.findPersonTlfnr(tlfnr, true);
		return p;
	}
	
	public Person findPersonId(int id)
	{
		return dbPer.findPersonId(id, true);
	}
	
	public void updatePerson(int personId, String navn, String adresse, String email, String cprnr, String tlfnr, String rabat, int postnrby)
	{
		Person person = new Person(personId,navn,adresse,email,cprnr,tlfnr,ctrRab.findRabat(rabat),ctrPos.findPostnrby(postnrby));
		dbPer.updatePerson(person);
	}
	
	public void createPerson(String navn, String adresse, String email, String cprnr, String tlfnr, String rabat, int postnr, String by)
	{
		Postnrby postnrby = ctrPos.findPostnr(postnr,by);
		Person p = new Person(navn,adresse,email,cprnr,tlfnr,ctrRab.findRabat(rabat),postnrby);
		dbPer.createPerson(p);
	}
	
	public void deletePerson(int personId)
	{
		dbPer.deletePerson(personId);
	}
}